package com.imageFilters;

import android.graphics.Bitmap;


public class GrayFilter implements ImageFilterInterface {
	private ImageData imageIn;
	
	public GrayFilter() {
		super();
	}
	
	public GrayFilter(Bitmap bmp) {
		super();
		this.imageIn = new ImageData(bmp);
	}

	public ImageData imageProcess(Bitmap bmp) {
		this.imageIn = new ImageData(bmp);
		return imageProcess();
	}
	
	public ImageData imageProcess() {
		
		int r,g,b,corfinal;
		for (int x = 0; x < imageIn.getWidth(); x++) {
			for (int y = 0; y < imageIn.getHeight(); y++) {
				r = imageIn.getRComponent(x, y);
				g = imageIn.getGComponent(x, y);
				b = imageIn.getBComponent(x, y);
				corfinal = (int)((r*0.3)+(b*0.59)+(g*0.11));
				imageIn.setPixelColor(x,y,corfinal,corfinal,corfinal);
			}
		}
		return imageIn;
	}

}
